package org.example.taskmaster.fragments;

import org.example.taskmaster.activities.MainActivity;
import android.app.ListFragment;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class TabsFragment extends ListFragment {
	// get contents of tabs from DetailsFragmentFactory
	private String [] tabs = DetailsFragmentFactory.getTabs();
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		
		// populate the tabs
		setListAdapter(new ArrayAdapter<String> (getActivity(),android.R.layout.simple_list_item_activated_1, tabs));
		
		// Allow one tab to be in "chosen" state
		getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
		
	}
	@Override
	public void onListItemClick(ListView l, View v, int position, long id) {
		// update the list to highlight the selected item
		getListView().setItemChecked(position, true);
		
		// refer to MainActivity to load a fragment into details area
		MainActivity main = (MainActivity) getActivity();
		main.loadDetailFragment(tabs[position]);
	}

}
